﻿// change to using the Decorated/extended Radio and Button
function EatAndDoit() {
    var silver = document.getElementById("silverlight");
    if (silver) {
        var content = silver.Content;
        if (content) {
            var sample = content.Demo6;
            if (sample) {
                var eat = sample.FindControl("#Eat");
                if (eat) {
                    eat.Value = true;

                    var doit = sample.FindControl("#Doit");
                    doit.DoClick();

                    var poll = function () 
                                {
                                    if (sample.IsProcessing)
                                        window.setTimeout(poll, 300);
                                    else
                                        alert(sample.FindControl("#Result").Text);
                                };
                                
                    window.setTimeout(poll, 500);
                }
                else
                    alert('Error: could not find EatControl radio control!');
            }
            else
                alert('Error: could not find sample silverlight usercontrol');
        }
        else {
            alert('Error: could not find silverlight content!');
        }
    }
    else {
        alert('Error: Could not found silverlight control');
    }
}
